#include<iostream>
#include<vector>;
using namespace std;
class solution{
    public:
    int search(vector<int>& nums,int target)
    {
        int left = 0;
        int right = nums.size()-1;
        while(left<=right)
        {
            int middle = left +((right - left)/2);
            if(nums[middle] > target)//说明此时middle一定不是target
            {
                right = middle -1 ;
            }
            else if(nums[middle] < target)
            {
                left= middle;
            }
            else 
            {
                return middle;
            }
        }
        return -1;
    }
};
int main()
{
    vector<int> test_nums = {-1,2,3,5,7,22};
    solution test;
    int result;
    result = test.search(test_nums,7);
    cout<<"result = "<<result<<endl;
}
